home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-11-05 | 4.6 KB | 164 lines | [TEXT/CWIE] |
- /*************************************************************************************
- #
- TShipSprite.cp
-
- This is the class used to represent the friendly ship in the game. The enemy ship
- is only slightly different, so there might be some opportunity to combine the TEnemySprite
- and TShipSprite classes.
-
- Author: Timothy Carroll
- Apple Developer Technical Support
- timc@apple.com
-
- Modification History:
-
- 1/23/97 TMC Added include for Moofwars.h so that MrC will compile
- 8/15/96 TMC Initial Release
-
- Copyright © 1996, 1997 Apple Computer, Inc., All Rights Reserved
-
-
- You may incorporate this sample code into your applications without
- restriction, though the sample code has been provided "AS IS" and the
- responsibility for its operation is 100% yours. However, what you are
- not permitted to do is to redistribute the source as "DSC Sample Code"
- after having made changes. If you're going to re-distribute the source,
- we require that you make it clear in the source that the code was
- descended from Apple Sample Code, but that you've made changes.
-
- *************************************************************************************/
-
- #include "Moofwars.h"
- #include "TShipSprite.h"
- #include "TShotSprite.h"
-
- TShipSprite::TShipSprite (TShipSpriteData *data):
- TSprite((TSpriteData *) data)
- {
- fRotateInterval = data->rotateInterval;
- fRotateValue = 0;
- fShotInterval = data->shotInterval;
- fShotValue = 0;
- fDirection = fFace;
- fShotsGroup = data->shotsGroup;
- }
-
-
- TShipSprite::~TShipSprite (void)
- {
- }
-
- void
- TShipSprite::ProcessSprite (void)
- {
-
- // Fire a shot
- if (CheckKey ((unsigned char *) &gCommandKeys, kShipFireShot) && fShotValue == 0)
- {
- TShotSpriteData shotData;
- TShotSprite *shot;
-
- #if qUsingSound
- if (gPlayingSound)
- HY_PlaySoundHandle (3, gSounds[4], NULL, 0, true);
- #endif
- // Set the firing delay so that we don't necessarily shoot every frame.
- fShotValue = fShotInterval;
-
- shotData.spriteData.spriteType = TShotSprite::kSpriteType;
- shotData.spriteData.visibility = kVisible;
- shotData.spriteData.face = 0;
- shotData.spriteData.collectionID = 1001;
- shotData.spriteData.preloadedCollection = NULL;
- shotData.duration = 30;
-
- shotData.spriteData.initialX = fCoordX - 80*gCosLookup [fDirection];
- shotData.spriteData.initialY = fCoordY - 80*gSinLookup [fDirection];
- shotData.spriteData.initialXVelocity = fVelocityX - 30*gCosLookup[fDirection];
- shotData.spriteData.initialYVelocity = fVelocityY - 30*gSinLookup [fDirection];
-
- shot = new TShotSprite (&shotData);
- shot->AddToGroup (fShotsGroup);
-
- }
-
- // Fire a cluster
- if (CheckKey ((unsigned char *) &gCommandKeys, kShipFireCluster) && fShotValue == 0)
- {
- TShotSpriteData shotData;
- TShotSprite *shot;
- #if qUsingSound
- if (gPlayingSound)
- HY_PlaySoundHandle (3, gSounds[4], NULL, 0, true);
- #endif
- // Set the firing delay so that we don't necessarily shoot every frame.
- fShotValue = fShotInterval;
-
- shotData.spriteData.spriteType = TShotSprite::kSpriteType;
- shotData.spriteData.visibility = kVisible;
- shotData.spriteData.face = 0;
- shotData.spriteData.collectionID = 1001;
- shotData.spriteData.preloadedCollection = NULL;
- shotData.duration = 30;
-
- for (int loop = 0; loop < 48; loop++) // one shot in every direction
- {
- shotData.spriteData.initialX = fCoordX - 80*gCosLookup[loop];
- shotData.spriteData.initialY = fCoordY - 80*gSinLookup[loop];
- shotData.spriteData.initialXVelocity = fVelocityX - 30*gCosLookup[loop];
- shotData.spriteData.initialYVelocity = fVelocityY - 30*gSinLookup[loop];
-
- shot = new TShotSprite (&shotData);
- shot->AddToGroup (fShotsGroup);
- }
-
- }
-
- // Rotate right
- if (CheckKey ((unsigned char *) &gCommandKeys, kShipRotateRight) && fRotateValue == 0)
- {
- fDirection = (fDirection+1) % 48;
- fRotateValue = fRotateInterval;
- }
-
- // Rotate left
- if (CheckKey ((unsigned char *) &gCommandKeys, kShipRotateLeft) && fRotateValue == 0)
- {
- fDirection = (fDirection+47) % 48;
- fRotateValue = fRotateInterval;
- }
-
- // Thrust. The fCurrentFace is used so that we can provide different frames
- // if we have thrust active.
-
- if (CheckKey ((unsigned char *) &gCommandKeys, kShipApplyThrust) )
- {
- fVelocityY -= gSinLookup[fDirection] >> 1;
- fVelocityX -= gCosLookup[fDirection] >> 1;
- fFace = fDirection;
- }
- else
- fFace = fDirection;
-
- // Adjust our intervals before we can turn/shoot again.
- if (fRotateValue > 0)
- fRotateValue--;
-
- if (fShotValue > 0)
- fShotValue--;
-
- // Process our ship's movement
- TSprite::ProcessSprite();
- TSprite::Bounce (&gWorldBounds);
- }
-
-
- void
- TShipSprite::Collision (TSprite *theSprite)
- {
- #if qUsingSound
- if (gPlayingSound)
- HY_PlaySoundHandle (4, gSounds[5], NULL, 0, false);
- #endif
- #pragma unused (theSprite)
- }